<?php
class Admin_Form_Company extends Zend_Form {
	
	const COMPANYNAME 	= 'Tên công ty';
	const ADDRESS 		= 'Địa chỉ';
	const HOTLINE 		= 'Hotline';
	const NICKSKYPE 	= 'Nick skype';
	const NICKYAHOO 	= 'Nick yahoo';
	
	const ENCODING		= 'UTF-8';
	const NAME_MIN_LENGTH    	= 5;
	const NAME_MAX_LENGTH    	= 100;
	
    public function init() {
    	$this->setName('frmCompany');
    	
    	$company_name = $this->addCompanyName();
    	$address = $this->addAddress();
    	$hotline = $this->addHotline();
    	$nickskype = $this->addNickSkype();
    	$nickyahoo = $this->addNickYahoo();
    	
    	$this->addElements(array($company_name, $address, $hotline, $nickskype, $nickyahoo));
    }
    
	private function addCompanyName() {
        $nameNotEmpty = new Zend_Validate_NotEmpty();
        //Length validate
        $nameLength = new Zend_Validate_StringLength(self::NAME_MIN_LENGTH, self::NAME_MAX_LENGTH, self::ENCODING);
        $name = new Zend_Form_Element_Text('cty_ten');
        $name	->setLabel(self::COMPANYNAME)
        		->addFilter('StripTags')
        		->addFilter('StringTrim')
        		->setRequired(true)
        		->addValidator($nameNotEmpty, true)
        		->addValidator($nameLength);
        return $name;
	}
	
	protected function addAddress() {
		$notEmptyAddress = new Zend_Validate_NotEmpty();
		$address = new Zend_Form_Element_Text('cty_dia_chi');
		$address->setLabel(self::ADDRESS)
         		->addFilter('StripTags')
         		->addFilter('StringTrim')
         		->setRequired(true)
         		->addValidator($notEmptyAddress, true);
        
        return $address;
	}
	
	protected function addHotline() {
		$notEmptyHotline = new Zend_Validate_NotEmpty();
		$hotline = new Zend_Form_Element_Text('cty_hotline');
		$hotline->setLabel(self::HOTLINE)
         		->addFilter('StripTags')
         		->addFilter('StringTrim')
         		->setRequired(true)
         		->setDescription('Hãy nhập theo định dạng \'số điện thoại-tên\'')
         		->addValidator($notEmptyHotline, true);
        
        return $hotline;
	}
	
	protected function addNickSkype() {
		$notEmptyNickSkype = new Zend_Validate_NotEmpty();
		$nickskype = new Zend_Form_Element_Text('cty_nick_skype');
		$nickskype->setLabel(self::NICKSKYPE)
        		  ->addFilter('StripTags')
         		  ->addFilter('StringTrim')
         		  ->setRequired(true)
         		  ->setDescription('Hãy nhập theo định dạng \'nick-tên\'')
         		  ->addValidator($notEmptyNickSkype, true);
        
        return $nickskype;
	}
	
	protected function addNickYahoo() {
		$notEmptyNickYH = new Zend_Validate_NotEmpty();
		$nickyahoo = new Zend_Form_Element_Text('cty_nick_yahoo');
		$nickyahoo->setLabel(self::NICKYAHOO)
         		->addFilter('StripTags')
         		->addFilter('StringTrim')
         		->setRequired(true)
         		->setDescription('Hãy nhập theo định dạng \'nick-tên\'')
         		->addValidator($notEmptyNickYH, true);
        
        return $nickyahoo;
	}
}